#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
ll dp[65][65];
void init() {
  rep(i, 0, 60) rep(j, 0, 60) dp[i][j] = 1e18;
  dp[0][0] = 0;
  rep(x, 1, 60) per(i, 60, 0) per(j, 60, 0) {
    if (dp[i][j] == 1e18) continue;
    if (i + x <= 60) dp[i + x][j] = min(dp[i + x][j], dp[i][j] + (1ll << x));
    if (j + x <= 60) dp[i][j + x] = min(dp[i][j + x], dp[i][j] + (1ll << x));
  }
}
void solve() {
  ll x, y;
  cin >> x >> y;
  ll ans = 1e18;
  rep(i, 0, 60) rep(j, 0, 60) {
    if ((x >> i) == (y >> j)) ans = min(ans, dp[i][j]);
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  init();
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}